package IBBB.view;

import IBBB.model.UserMessage;
import IBBB.model.WordStockMessage;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableMap;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.scene.text.Text;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class SelectWordStock extends FlowPane {
    private UserMessage userMessage;
    private ObservableMap<StringProperty, List<IntegerProperty>> userSchedule;
    private WordStockMessage wordStockMessage;
    private StackPane container;


    public SelectWordStock(UserMessage message, WordStockMessage wordStockMessage, StackPane caller) throws IOException {
        this.wordStockMessage = wordStockMessage;
        userMessage = message;
        userSchedule = message.getWordStockInfo();
        container = caller;
        //this.setPadding(new Insets(10));
        //this.setOrientation(Orientation.VERTICAL);
        this.setVgap(10.0);
        initialize();
    }

    public void initialize() throws IOException {
        this.getChildren().clear();
        if (userSchedule.entrySet().size() == 0) {
            Label label = new Label();
            label.setText("\n\n\n      还没有计划，快去新建一个吧~");
            label.setFont(new Font(25));
            this.getChildren().add(label);
            return;
        }
        ObservableMap<String, Integer> map = wordStockMessage.getMessage();
        for (Map.Entry<StringProperty, List<IntegerProperty>> item: userSchedule.entrySet()) {
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(getClass().getResource("ScheduleBox.fxml"));
            HBox box = loader.load();
            ScheduleBox boxController = loader.getController();
            System.out.println(item.getKey());//TODO
            boxController.setScheMessage(item.getKey(), item.getValue().get(0), map.get(item.getKey().get()), item.getValue().get(1));
            boxController.setCaller(container, userMessage);
            this.getChildren().add(box);
        }
    }
}
